package com.leetcode.hot100;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @BelongsProject: LeetCode
 * @BelongsPackage: com.leetcode.hot100
 * @Author: lei
 * @CreateTime: 2024-03-30  10:33
 * @Description: TODO
 * @Version: 1.0
 */
public class 矩阵置零 {
    public static void main(String[] args) {
        //int[][] matrix = {{1, 1, 1}, {1, 0, 1}, {1, 1, 1}};
        int[][] matrix = {{7, 1, 1, 9, 1}, {8, 0, 4, 7, 6}};
        setZeroes(matrix);
    }

    public static void setZeroes(int[][] matrix) {
        ArrayList<String> arrayList = new ArrayList<>();
        // x:表示行 y:表示列
        for (int x = 0; x < matrix.length; x++) {
            for (int y = 0; y < matrix[x].length; y++) {
                int current = matrix[x][y];
                if (current == 0) {
                    String index = x + "," + y;
                    arrayList.add(index);
                }
            }
        }
        for (String split : arrayList) {
            int s1 = Integer.parseInt(split.split(",")[0]);
            int s2 = Integer.parseInt(split.split(",")[1]);
            for (int x = 0; x < matrix.length; x++) {
                for (int y = 0; y < matrix[x].length; y++) {
                    if (x == s1 || y == s2) {
                        matrix[x][y] = 0;
                    }
                }
            }
        }
        System.out.println(Arrays.deepToString(matrix));
    }
}

